#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#define FILE_NAME "bite.txt"
int main()
{
    //打开文件
    int fd = open(FILE_NAME, O_CREAT | O_WRONLY | O_TRUNC, 0666);
    if(fd == -1)
    {
        perror("file open");
    }
    //写入文件
    const char* str = "linux is easy\n";
    write(fd, str, strlen(str));
    close(fd);
    //读出文件
    fd = open(FILE_NAME, O_RDONLY);
    char arr[20] = {0};
    read(fd, arr,sizeof(arr));
    printf("%s", arr);
    //关闭文件
    close(fd);
    return 0;
}
